<template>
  <div class="mainsu">
    <div class="main_spac1">
      <div class="main_white padding10 paddingBottom20">
        <div class="mainor_form">
          <div class="mainor_te">
            <router-link to="/warehouse/withdrawal/add" class="mainor_tea"
              >创建出库单</router-link
            >

          </div>
          <el-form
            :inline="true"
            :model="form"
            class="demo-form-inline"
            ref="userListFrom"
            label-width="70px"
          >
            <el-form-item label="出库状态" prop="status">
              <el-select
                v-model.trim="form.status"
                placeholder="出库状态"
                class="wid220"
              >
                <el-option label="所有" value=""></el-option>
                <el-option
                  v-for="(statusList, index) in list.statusList"
                  :key="index"
                  :label="statusList"
                  :value="parseInt(index + 1)"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="出库类型" prop="type">
              <el-select
                v-model.trim="form.type"
                placeholder="出库类型"
                class="wid220"
              >
                <el-option label="所有" value=""></el-option>
                <el-option
                  v-for="(typeList, index) in list.typeList"
                  :key="index"
                  :label="typeList"
                  :value="parseInt(index)"
                ></el-option>
              </el-select>
            </el-form-item>
            <div class="more el-form-item" @click="more">
              <span>更多</span>
              <i :class="[{on:moredata},' el-icon-arrow-down']"></i>
            </div>
            <div class="clearfix"></div>
            <el-collapse-transition>
              <div v-if="moredata">
                <el-form-item label="出库单号" prop="order_sn">
                  <el-input
                    v-model.trim="form.order_sn"
                    placeholder="出库单号"
                    clearable
                    class="wid220"
                  ></el-input>
                </el-form-item>
                <el-form-item label="关联单号" prop="related_order_sn">
                  <el-input
                    v-model.trim="form.related_order_sn"
                    placeholder="关联单号"
                    clearable
                    class="wid220"
                  ></el-input>
                </el-form-item>
                <el-form-item label="创建日期" prop="establishTime">
                  <el-date-picker
                    v-model="establishTime"
                    type="daterange"
                    class="time220"
                    :editable="false"
                    unlink-panels
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    value-format="yyyy-MM-dd"
                    :clearable="false"
                    :picker-options="pickerOptions"
                  />
                </el-form-item>
                <el-form-item label="出库时间" prop="createTime">
                  <el-date-picker
                    v-model="createTime"
                    type="daterange"
                    class="time220"
                    :editable="false"
                    unlink-panels
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    value-format="yyyy-MM-dd"
                    :clearable="false"
                    :picker-options="pickerOptions"
                  />
                </el-form-item>
                <div class="clearfix"></div>
              </div>
            </el-collapse-transition>
            <el-form-item class="marginTop10">
              <el-button
                class="reset marginLeft10"
                type="primary"
                @click="$refs['userListFrom'].resetFields()"
              >重置</el-button>
              <el-button type="primary" @click="getArticleList" :loading="listLoading">搜索</el-button>
            </el-form-item>
          </el-form>
        </div>
        <div class="main_table marginTop10" style="min-height:550px">
          <el-table
            ref="multipleTable"
            v-loading="listLoading"
            :data="list.list.data"
            element-loading-text="加载中"
            fit
            border
            highlight-current-row
          >
            <el-table-column label="出库单号" width="200" prop="order_sn" />
            <el-table-column></el-table-column>
            <el-table-column label="出库类型" width="120">
              <template slot-scope="scope">{{
                list.typeList[scope.row.type]
              }}</template>
            </el-table-column>
            <el-table-column></el-table-column>
            <el-table-column label="关联单号" width="200" prop="related_order_sn" />
            <el-table-column></el-table-column>
            <el-table-column label="出库金额" width="120" prop="money" />
            <el-table-column label="出库状态" width="120" prop="status" >
              <template slot-scope="scope">{{
                list.statusList[scope.row.status]
              }}</template>
            </el-table-column>
            <el-table-column label="创建时间" width="120" prop="created_at" >
              <template slot-scope="scope">{{
                parseTime(scope.row.created_at, "{y}-{m}-{d}")
              }}</template>
            </el-table-column>
            <el-table-column label="出库时间" width="120" prop="updated_at" >
              <template slot-scope="scope">{{
                parseTime(scope.row.stock_out_time, "{y}-{m}-{d}")
              }}</template>
            </el-table-column>
            <el-table-column></el-table-column>
            <el-table-column
              label="管理操作"
              align="center"
              fixed="right"
              width="200"
              class-name="main_hei"
            >
              <template slot-scope="scope">
                <router-link :to="'/warehouse/withdrawal/see/' + scope.row.id">
                  <el-link type="success">查看</el-link>
                </router-link>
                <el-link>打印</el-link>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="main_page boxdq">
          <div></div>
          <!-- 分页 -->
          <div class="main_page_r">
            <el-pagination
              :current-page="current.page"
              :page-sizes="[20, 30, 50, 100]"
              :page-size="limit"
              layout="total, sizes, prev, pager, next, jumper"
              :total="totalCount"
              background
              @size-change="changeLimit"
              @current-change="changePage"
            />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {
  stockOut_index,
} from "@/api/warehouse/warehouseWithdrawal";
import { apiUrl, objKeySort, Md5 } from "@/utils/public";
import dateOption from "@/options/dateOption";
import { parseTime } from "@/utils/index";

export default {
  components: {},
  data() {
    return {
      // 时间
      parseTime,
      // 分页
      current: {
        page: 1,
        per_page: 20,
      },
      limit: 20,
      totalCount: 1,
      // 列表数据
      list: {
        list: [],
      },
      listLoading: false,
      // 搜索
      form: {
        status: null,
        type: null,
        order_sn: "",
        related_order_sn: "",
        stockOut_start_time: "",
        stockOut_end_time: "",
        start_time: "",
        end_time: "",
      },
      createTime: [],
      establishTime: [],
      pickerOptions: dateOption,
      // 更多
      moredata: false,
    };
  },
  created() {
    // 列表
    this.stockOut_index();
  },
  methods: {
    // 导出明细 
    export_de(){
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name, this.list_form())) +
              apiUrl().appsecret
          ),
        },
        apiUrl().name,
        this.list_form()
      );
      stockOut_indexw(data).then((res) => {
        if (res.errcode == 0) {
          this.$message({
            message: "导出成功",
            type: "success",
          });
        } else {
          this.$message.error(res.errmsg);
        }
      });
    },
    // 搜索
    getArticleList() {
      this.current.page = 1;
      this.stockOut_index();
    },
    // 分页
    changeLimit(pageSize) {
      this.current.per_page = pageSize;
      this.stockOut_index();
    },
    changePage(page) {
      this.current.page = page;
      this.stockOut_index();
    },
    // 更多
    more() {
      this.moredata = !this.moredata;
    },
    // 列表
    stockOut_index() {
      this.listLoading = true;
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(
              Object.assign(apiUrl().name, this.list_form(), this.current)
            ) + apiUrl().appsecret
          ),
        },
        apiUrl().name,
        this.list_form(),
        this.current,
      );
      stockOut_index(data).then((res) => {
        this.listLoading = false;
        if (res.errcode == 0) {
          this.list = res.data;
          this.totalCount = res.data.list.total;
        } else {
          this.$message.error(res.errmsg);
        }
      });
    },
    list_form() {
      let form = JSON.parse(JSON.stringify(this.form));
      form.start_time = this.createTime[0] ? this.createTime[0] : "";
      form.end_time = this.createTime[1] ? this.createTime[1] : "";
      form.stockOut_start_time = this.establishTime[0]
        ? this.establishTime[0]
        : "";
      form.stockOut_end_time = this.establishTime[1] ? this.establishTime[1] : "";

      return form;
    },
  }
};
</script>
<style lang="scss" scoped>
@import "@/styles/variables.scss";

.mainsu {
  .mainor_form form {
    width: calc(100% - 180px);
  }
}
</style>
